<template>
	<view class="inviteFd" @longpress="show = true">
		<!-- <image ref="image" class="bc" src="../../static/inviteFd/bc.jpg" mode="aspectFill">
		<view class="wenb">敬请期待</view>
		</image> -->
		<!-- #ifdef APP-PLUS -->
		<u-modal :show="show" title="是否保存邀请二维码" showCancelButton :closeOnClickOverlay="true" @cancel="show = false" @close="show = false" @confirm="save"></u-modal>
		<!-- #endif -->
		<template>
		    <view>
		        <shareImages ref="canvas" :canvasWidth="canvasWidth" :canvasHeight="canvasHeight" :shareTitle="shareTitle" :goodsTitle="goodsTitle" :shareImage="shareImage" :qrSize="qrSize" :qrUrl="qrUrl" @success="shareSuccess"></shareImages>
		    </view>
		</template>
	</view>
</template>

<script>
	import shareImages from '@/components/hj-placard/shareImages.vue'
	import Config from 'common/config.js'
	export default {
		components: { shareImages },
		data() {
			return {
				qrcodeImg: '',    //二维码本地图片,
				// imageHeight: '',
				show: false,
				canvasWidth:375,    // 宽度
				canvasHeight:500,   // 高度
				shareTitle:'',     // 分享标题
				goodsTitle:'',// 商品宣传标题
				shareImage:'../../static/inviteFd/bc.jpg',   // 背景图片
				qrSize: 200,    // 二维码大小
				qrUrl: '',  // 生成二维码的链接
			}
		},
		onLoad() {
			let sysinfo = uni.getSystemInfoSync()
			this.canvasHeight = sysinfo.windowHeight
			this.canvasWidth = sysinfo.windowWidth
			let userId = uni.getStorageSync('userId')
			this.qrUrl = Config.codeUrl + ':998/index.html?userId='+userId
		},
		methods: {
			// 回调图片地址
			shareSuccess(e){
				this.qrcodeImg = e
			},
			// 保存二维码
			save() {
				let that = this
				uni.saveImageToPhotosAlbum({
					filePath: that.qrcodeImg,
					success: function(res) {
						console.log('保存成功');
						uni.showToast({
							icon: 'none',
							title: '保存成功'
						})
						that.show = false
					},
					fail() {
						uni.showToast({
							icon: 'none',
							title: '保存失败'
						})
						that.show = false
					}
				});
			}
		},
		mounted() {
			this.$refs.canvas.canvasCreate();
		}
	}
</script>

<style scoped lang="scss">
</style>
